<!--
 * @Author: 15097322811 1447934599@qq.com
 * @Date: 2024-01-16 10:17:31
 * @LastEditors: 15097322811 1447934599@qq.com
 * @LastEditTime: 2024-02-04 18:17:50
 * @Description: 
-->
<script>
	const normalPlatformList = ["ios", "android", "devtools"];
	// var qiyuModule = uni.requireNativePlugin('Netease-QiyuModule');
	// const modal = uni.requireNativePlugin('modal');
	// const appKey = '3e4baa02f20ca8a40fe94a01ffd8a72d';
	// #ifdef APP-PLUS
	var jpushModule = uni.requireNativePlugin("JG-JPush");
	import unipush from "@/utils/unipush.js";
	// #endif
	export default {
		onError(err) {
			console.log(err)
		},
		async onLaunch(par) {
			const langArray = ['en', 'zh-cn', 'br', 'in', 'tl']
			let lang = uni.getStorageSync('mhlanguage') || null; //获取缓存的语言设置
			const sysLang = uni.getSystemInfoSync().language.toLowerCase(); // 获取系统语言
			// 如果缓存中没有，系统语言也没有就调用ip获取语言
			if (langArray.indexOf(lang ? lang : sysLang) === -1) {
				lang = await this.getIPLang();
			}
			uni.setStorageSync("mhlanguage",lang ? lang : sysLang);
			// 请求语言的域名
			await this.getDomain();
			this.$i18n.locale = lang ? lang : sysLang; //设置语言
			// if(uni.getStorageSync("mhlanguage") !== uni.getLocale()) {
			// 	uni.setLocale(lang ? lang : sysLang)
			// }
			// #ifdef APP-PLUS
			unipush();
			// 获取本地应用资源版本号
			plus.runtime.getProperty(plus.runtime.appid, (info) => {
				const mhversion = JSON.stringify(info.version);
				// console.log('version', JSON.parse(mhversion));
				this.$http({
					url: "/api/common/getversion",
					data: {
						version: JSON.parse(mhversion) || "",
					},
				}).then((res) => {
					uni.setStorageSync('mhstatus',res.data.data.status)
				});
			})
			// #endif
			if (["windows", "mac"].some((v) => v === wx.getStorageSync("platform"))) {
				uni.setStorageSync("isPcOpen", true);
				console.log("pc端");
			} else {
				uni.setStorageSync("isPcOpen", false);
				console.log("移动端");
			}
		},
		onLoad(par) {

		},
		onShow(options) {
			// this.exitApp();
		},
		onHide() {
			this.closeMusic();
		},
		methods: {
			// 通过ip获取语言
			async getIPLang() {
				return new Promise((resolve,reject) => {
					this.$http({
						url: "language/domain",
						method: 'GET'
					})
					.then((res) => {
						// 如果语言为空，跳转切换语言页面
						if (!res.data.data.lang) {
							uni.reLaunch({
								url: "/pages/my/changeLanguage",
							});
						}
						resolve(res.data.data.lang)
					}).catch((err) => {
						reject(err);
					});
				})
			},
			// 获取域名
			async getDomain() {
				return new Promise((resolve,reject) => {
					this.$http({
						url: "language/domain",
						method: 'GET',
						data: {
							"lang": uni.getStorageSync('mhlanguage') || null
						}
					})
					.then((res) => {
						if (res.data.data.domain) {
							uni.setStorageSync("languageDomain",res.data.data.domain + "/");
						}
						// 获取结束执行业务逻辑
						this.$isResolve();
						resolve(res.data.data.domain)
					}).catch((err) => {
						reject(err);
					});
				})
			},
			//退出应用
			exitApp() {
				// #ifdef APP-PLUS
				let main = plus.android.runtimeMainActivity();
				main.moveTaskToBack(false);
				// #endif
			},
			//关闭音乐
			closeMusic() {
				this.$music.playBgm({
					mute: true,
				});
				uni.setStorageSync("muteBgMusic", this.muteBgMusic);
			},
		},
	};
</script>
<style>
/* 	page {
		background-color: rgb(253, 235, 199);
		
	} */
</style>
<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
	@import url("static/css/base.scss");

	table {
		width: 100% !important;
	}

	uni-toast {
		z-index: 999999999999;
	}

	.line_1 {
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	::v-deep .u-tabbar {
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		box-sizing: content-box;
	}

	::v-deep .u-tabbar__content__item__text text {
		font-size: 20rpx;
		line-height: 23rpx;
	}

	@font-face {
		font-family: 'YouSheBiaTiHei';
		src: url("@/static/font/YouSheBiaTiHei.ttf");
	}

	//#ifndef  MP-WEIXIN
	@font-face {
		font-family: YouSheBiaTiHei1111;
		src: url("@/static/font/YouSheBiaTiHei.ttf");
	}

	//#endif
	//#ifdef  MP-WEIXIN
	@font-face {
		font-family: YouSheBiaTiHei;
		src: url("https://www.sjmanghe.com/YouSheBiaTiHei.ttf");
	}

	//#endif

	// @font-face {
	// 	font-family: "myfont";
	// 	src: url('@/font/YouSheBiaoTiHei.ttf') format("truetype");
	// }
</style>